<template>
	<view>
		<u-navbar title="频道详情" :border-bottom="false" back-icon-color="#f1f1f1" title-color="#f1f1f1" :background="navbarBackground"></u-navbar>
		<view class="main">
			<u-image width="100%" height="400" :src="channel.banner"></u-image>
			<view class="info">
				<text class="info-title">{{ channel.title }}</text>
				<view class="info-sub">
					<text>{{ `已更新：${videoList.length}期` }}</text>
				</view>
			</view>
			<view class="info-content">
				<text class="info-title">话题列表</text>
				<view class="list" v-if="videoList.length !== 0">
					<view class="item" v-for="(item, index) in videoList" :key="index" @click="handleToLive(item)">
						<text class="item-status status-notice" v-show="item.status == -1">预告</text>
						<text class="item-status status-live" v-show="item.status == 1 || item.status == 2">直播</text>
						<text class="item-status status-replay" v-show="item.status == 0">回放</text>
						<u-image width="100%" height="200" :src="item.banner"></u-image>
						<view class="item-info">
							<text class="item-title">{{ item.title }}</text>
							<text class="item-time">{{ item.start_time.slice(0, 16) }}</text>
							<view class="item-pv">
								<u-image width="35" height="35" :src="require('../../../static/image/pv.png')"></u-image>
								<text>{{ item.pv }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			navbarBackground: {
				backgroundImage: 'linear-gradient(90deg, rgb(27,52,92), rgb(49,84,142))'
			},
			info: {},
			channel: {},
			videoList: []
		};
	},
	onLoad(option) {
		// #ifdef MP-WEIXIN
		uni.showShareMenu({
			withShareTicket: true,
			menus: ['shareAppMessage', 'shareTimeline']
		});
		// #endif
		let id = option.cid;
		this.getChannelInfo(id);
	},
	methods: {
		getChannelInfo(id) {
			this.$u
				.post('/channel/get_channel_info', {
					cid: id
				})
				.then(res => {
					this.channel = res.dataobj;
				});
			this.$u
				.post('/channel/get_channel_topic_list', {
					cid: id
				})
				.then(res => {
					this.videoList = res.dataobj;
				});
		},
		handleToLive(obj) {
			let state = uni.getStorageSync('login_state');
			if (state) {
				uni.setStorageSync('live', obj);
				uni.navigateTo({
					url: '../live/live'
				});
			} else {
				uni.showToast({
					title: '请先登录',
					icon: 'none'
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.main {
	.info {
		padding: $uni-spacing-col-lg $uni-spacing-row-lg;
		background-color: #fff;

		.info-title {
			display: inline-block;
			padding-bottom: $uni-spacing-col-lg;
			font-size: 1rem;
			color: #587bb9;
		}

		.info-sub {
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #999;
			font-size: 9pt;
		}
	}

	.info-content {
		margin-top: $uni-spacing-col-lg;
		padding: $uni-spacing-col-lg $uni-spacing-row-lg;
		background-color: #fff;

		.info-title {
			color: #587bb9;
		}

		.list {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			margin-top: $uni-spacing-col-lg;

			.item {
				position: relative;
				width: 49%;
				display: flex;
				flex-direction: column;
				background-color: #fff;
				margin: 12rpx 0;
				border-radius: 10rpx;
				box-shadow: 0 5rpx 10rpx #eee;
				overflow: hidden;

				.item-status {
					padding: 7rpx 15rpx;
					position: absolute;
					top: 0;
					left: 0;
					z-index: 1;
					color: #f1f1f1;
					font-size: 8pt;
					border-bottom-right-radius: 10rpx;
				}

				.status-notice {
					background-color: #587bb9;
				}

				.status-live {
					background-color: #2f4b7a;
				}

				.status-replay {
					background-color: #b68538;
				}

				.item-info {
					padding: $uni-spacing-col-sm $uni-spacing-row-sm;
					display: flex;
					flex-direction: column;

					.item-title {
						font-size: 12pt;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						font-weight: bold;
						padding: $uni-spacing-col-sm 0;
					}

					.item-time {
						padding: $uni-spacing-col-base 0;
						color: #999;
					}

					.item-pv {
						padding: $uni-spacing-col-sm;
						display: flex;
						align-items: center;
						flex-grow: 15rpx;

						text {
							padding-left: 15rpx;
						}
					}
				}
			}
		}
	}

	.channel {
		display: flex;
		align-items: center;
		padding: $uni-spacing-col-lg $uni-spacing-row-lg;
		margin-top: $uni-spacing-col-sm;
		background-color: #fff;

		.channel-right {
			padding: $uni-spacing-col-lg 0 $uni-spacing-col-lg $uni-spacing-row-sm;
			height: 200rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			flex: 1;

			.more {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 1rem;
			}
		}
	}
}
</style>
